package com.wave.wavesystem.ai.test.docquery;

import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.generation.augmentation.ContextualQueryAugmenter;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;
import org.springframework.stereotype.Component;

/**
 * 检索真强顾问
 */
public class RagCustomAdvisorFactory {

    /**
     * 创建自定义的 rag 检索增强顾问
     *
     * @param wavePgVectorStore
     * @param status
     * @return
     */
    public static Advisor createRagCustomAdvisorFactory(VectorStore wavePgVectorStore, int status) {
        // 过滤特定的条件
        Filter.Expression expression = new FilterExpressionBuilder()
                .eq("status", status)
                .build();

        VectorStoreDocumentRetriever build = VectorStoreDocumentRetriever.builder()
                .vectorStore(wavePgVectorStore)
                .filterExpression(expression)
                .similarityThreshold(0.0)
                .topK(2)
                .build();


        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(build) // 文档检索器
                .queryAugmenter(ContextualQueryAugmenter.builder().allowEmptyContext(true).build())// 文档增强器
                .build();

    }
}
